package com.example.forum.controller;

import com.example.forum.common.AppResult;
import com.example.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "测试接口")
@Slf4j
// 指定测试根路径映射地址前缀
@RequestMapping("/test")
// Controller注解，返回的对象⽤JSON形式表⽰
@RestController
public class TestController {

    @ApiOperation("hello测试")
    @GetMapping("/hello")
    public String hello() {
        return "Hello, Spring Boot...";
    }

    @ApiOperation("异常测试")
    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个Exception...");
    }

    @GetMapping("/appException")
    public String testApplicationException() {
        throw new ApplicationException("这是⼀个⾃定义的ApplicationException");
    }
}
